﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using YwangHRMSys.DAL;
using YwangHRMSys.Model;


namespace YwangHRMSys.UI.SystemMgr.ContractMgr
    {
        /// <summary>
        /// ContractInfoWindowList.xaml 的交互逻辑
        /// </summary>
        public partial class ContractInfoWindowList : Window
            {

                public ContractInfoWindowList()
                {
                    InitializeComponent();
                }

                private void LoadData()
                {
                    var dal = new ContractInfoDAL().ListAll();
                       
          
                  DataGridContractList.ItemsSource = dal;
             
                    ColemployeeName.ItemsSource = new EmployeeInfoDAL().ListAll();
                 
                }

                private void Window_Loaded( object sender, RoutedEventArgs e )
                {
                    LoadData();
                  

             //  ColEmployeeName.ItemsSource = new EmployeeInfoDAL().GetEmployeeByGuid();
                }
            // {4CCF5398-8C6B-471C-9966-678E477CC135}

                private void BtnAdd_Click( object sender, RoutedEventArgs e )
                {
                    ContractInfoWindowEdit edit = new ContractInfoWindowEdit();
                    //添加数据行为，添加成功，
                    edit.IsInsert = true;
                    if (edit.ShowDialog() == true)
                        {
                            //重新刷新一次数据库
                            LoadData();
                        }
                }

                private void BtnEdit_Click( object sender, RoutedEventArgs e )
                {


                    ContractInfoModel de = (ContractInfoModel)DataGridContractList.SelectedItem;
                    if (de == null)
                    {
                        MessageBox.Show("请选择行！");
                        return;
                    }

                    ContractInfoWindowEdit edit = new ContractInfoWindowEdit();
                    //添加数据行为，添加成功，重新刷新一次数据库
                    edit.IsInsert = false;
                    edit.EditGuid = de.Id;
             //     string oo=  string.Format("yyyy年MM月dd日");
              //  de.ContractSigned.ToString(oo);
                    //   MessageBox.Show(edit.EditGuid.ToString());
                    if (edit.ShowDialog() == true)
                   {
                       LoadData();
                   }
                }

                private void BtnSearch_Click(object sender, RoutedEventArgs e)
                {
                //    MessageBox.Show(ColTxtIsRenewed);
                }

                private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
                {
                    if (DateSignedPicker.SelectedDate != null)
                        {
                            DateTime span=(DateTime)DateSignedPicker.SelectedDate;
                            DateExpiresPicker.SelectedDate = span.AddYears(1);
                       
                    }

                   // 
                }

                private void BtnOldContractInfo_Click(object sender, RoutedEventArgs e)
                {
                    var select = (ContractInfoModel) DataGridContractList.SelectedItem;
                    if (select == null)
                    {
                        MessageBox.Show("没有选中任何行");
                        return;
                    }
                    var win = new OldContractWindowEdit();
                    win.EditGuid = select.Id;
                  //  MessageBox.Show(win.EditGuid.ToString());
                    if (win.ShowDialog()==true)
                        {
                            LoadData();
                        }
                }

                private void BtnOldContractInfoList_Click(object sender, RoutedEventArgs e)
                {
                    var win =new OldContractWindowList();
                    win.ShowDialog();
                }

            }
    }
